/*var nr = document.querySelectorAll(".nr");
var text = document.querySelectorAll(".text");
var sp = document.querySelectorAll(".sp");
var ca = document.querySelectorAll(".delete");
var to = document.querySelector(".to");
var sp1 = document.querySelector(".sp1");*/

/*for (let i = 0; i < 5; i++){
    /!*text[i].addEventListener("change",function(){
        var num = nr[i].innerHTML * text[i].value;
        sp[i].innerHTML = num;
    });*!/
    ca[i].addEventListener("click",function(){
        to.removeChild(this.parentNode)
    });
}*/
/*
var sum = 0;
for (let p = 0; p < text.length; p++){
    var t = sp[p].innerHTML;
    t = Number(t);
    console.log(t);
    sum += t;
    console.log(sum);
    text[p].addEventListener("change",function(){
        var num = nr[p].innerHTML * text[p].value;
        num = num.toFixed(2);
        sp[p].innerHTML = num;
        sum += Number(sp[p].innerHTML);
    });
    ca[p].addEventListener("click",function(){
        to.removeChild(this.parentNode)
    });
}
sp1.innerHTML = sum;
/!*var a = sp[0].innerHTML;
var b = sp[1].innerHTML;
var c = sp[2].innerHTML;
var d = sp[3].innerHTML;
var f = sp[4].innerHTML;
a = Number(a);
b = Number(b);
c = Number(c);
d = Number(d);
f = Number(f);
var sum = a + b + c + d + f;*!/*/


function s(){
    let li = document.querySelectorAll(".to > li");
//总价
    let all = document.querySelector(".sp1");
    let sum = 0;

    for (let i = 0; i < li.length; i++){
        var price = li[i].children[1].children[0].innerHTML;
        var num = li[i].children[1].children[1].value;
        var total = li[i].children[1].children[3].innerHTML = price * num;
        /*    console.log(li[i].children[1].children[0]);
         console.log(li[i].children[1].children[1]);*/
        console.log(li[i].children[1].children[3]);
        sum += total;
    }

    console.log(sum);
    all.innerHTML = sum.toFixed(2);
}
s();

var to = document.querySelector(".to");
var bu = document.querySelector(".bu");


//只要数量的input内容发生改变，小计和总价就要更新
let num_all = document.querySelectorAll(".to .text");
for (let j = 0; j < num_all.length; j++){
    num_all[j].addEventListener('change',s);
}

//删除操作后，再根据小计计算总价
let del_all = document.querySelectorAll(".to .delete");
for (let k = 0; k < del_all.length; k++){
    del_all[k].addEventListener('click',function(){
        to.removeChild(this.parentNode);
        bu.innerHTML = Number(bu.innerHTML) - 1;
        s();
    })
}






/*//获取li
var li_ = document.querySelectorAll('.to > li');
//获取单价
var nr = document.querySelectorAll(".nr");
//获取数量
var text = document.querySelectorAll(".text");
//获取单价乘以总价的和
var span7 = document.querySelectorAll(".span7");
//获取删除的节点
var del = document.querySelectorAll(".delete");
//获取总价
var sp1 = document.querySelector(".sp1");
//获取ul
var to = document.querySelector(".to");
var bu = document.querySelector(".bu");
setInterval(function(){
    var total = 0;
    for(var i = 0;i<li_.length;i++){
        /!*del[i].index= i;
         del[i].onclick=function(){
         text[this.index].value = 0;
         this.parentNode.parentNode.parentNode.removeChild(li_[this.index])
         };*!/
        var t = del[i].addEventListener("click",function(){
            to.removeChild(this.parentNode);
            bu.innerHTML = Number(bu.innerHTML) - 1;
        });
        var total_sm = nr[i].innerHTML*text[i].value;
        span7[i].innerHTML = total_sm.toFixed(2);
        total = parseFloat(span7[i].innerHTML) + total;
        sp1.innerHTML=total.toFixed(2);
    }
});*/


















